package com.itheima.thread06;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadDemo {
    public static void main(String[] args) {
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                5,//核心线程数
                10,//总线程数
                60,//空闲时间60之后关闭线程
                TimeUnit.SECONDS,//空闲时间60 “秒” 之后关闭线程
                new ArrayBlockingQueue<>(10),//阻塞队列，长度10
                Executors.defaultThreadFactory(),//默认创建线程方式
                new ThreadPoolExecutor.AbortPolicy()//默认拒绝模式
        );


        for (int i = 0; i < 20; i++) {
            MyRunable mr = new MyRunable();
            pool.submit(mr);
        }

        pool.shutdown();

    }
}
